<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<link rel="stylesheet" media="screen" href="css/docs.css"/>
<link rel="stylesheet" media="screen" href="lib/jqplot/jquery.jqplot.min.css"/>
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>

<script type="text/javascript" src="${ctx}/js/global_util.js"></script>

<h1 class="page-title">请假申请单 - 添加</h1>

<div class="container_12 clearfix leading">
    <h5>流水号：<strong id="administration_serial_number"> </strong></h5>

    <div class="side grid_12 leading">
        <form class="form has-validation" name="post_form" id="post_form">
            <div class="clear"></div>
            <div class="clearfix">
                <label for="form_type" class="form-label">请假事由 <em>*</em></label>
                <div class="form-input">
                    <select id="form_type">
                        <s:if test="#request.leaveTypes != null and #request.leaveTypes.size() > 0">
                            <s:iterator value="#request.leaveTypes" var="leave">
                                <option value="${leave.typeCode}">${leave.typeName}</option>
                            </s:iterator>
                        </s:if>
                        <s:else>
                            <option value="-1">没有找到考勤系统请假类型</option>
                        </s:else>
                    </select>

                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="form_reason" class="form-label"> 原因描述 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="form_reason" name="applyForm.reason" required="required" placeholder=""/>
                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="s_start_date" class="form-label">时间自 <em>*</em></label>
                <div class="form-input">
                    <input type="text" class="date" id="s_start_date" name="s_start_date" onfocus="WdatePicker({maxDate:$('#s_end_date').val(), dateFmt:'yyyy-MM-dd HH:mm'})" readonly="readonly" value='<s:date name="#request.applyForm.startDate" format="yyyy-MM-dd"/>'/>
                </div>
            </div>

            <div class="clear"></div>
            <div class="clearfix">
                <label for="s_end_date" class="form-label">时间至 <em>*</em></label>
                <div class="form-input">
                    <input type="text" class="date" id="s_end_date" name="s_end_date" onfocus="WdatePicker({minDate:$('#s_start_date').val(), dateFmt:'yyyy-MM-dd HH:mm'})" readonly="readonly" value='<s:date name="#request.applyForm.endDate" format="yyyy-MM-dd"/>'/>
                </div>
            </div>

            <input type="hidden" name="applyForm.typeName" id="typeName">
            <input type="hidden" name="applyForm.typeCode" id="typeCode">
            <input type="hidden" name="applyForm.serialNumber" id="form_serialNumber">
            <div class="form-action clearfix">
                <button class="button" type="button" onclick="checkForm()">添加</button>
                <button class="button" type="reset">重置</button>
                <a class="button" href="#${userType==1?"sign" : "public"}/administration-leave-apply-form.xhtml"> <span style="background:url(${ctx}/images/img/arrow_undo.png)" class="icon">&nbsp;</span>返回</a>
            </div>
        </form>
    </div>
</div>

<div class="clear"></div>

<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript">
    $(function(){
        var serial = createSerialNumber();
        $("#administration_serial_number").html(serial);
        $("#form_serialNumber").val(serial);
    });

    function checkForm(){
        if($("#form_type").val() == "-1"){
            alert("没有找到考勤系统配置请假类型，请检查。");
            return;
        }
        $("#typeCode").val($("#form_type").val())
        $("#typeName").val($("#form_type").find("option:selected").text())

        var form_reason = $("#form_reason").val();
        if(checkNull(form_reason)){
            alert("请填写原因描述");
            return;
        }
        var a_startDate = $("#s_start_date").val();
        if (checkNull(a_startDate)) {
            alert("请填写请假开始时间");
            return;
        }
        var a_endDate = $("#s_end_date").val();
        if (checkNull(a_endDate)) {
            alert("请填写请假结束时间");
            return;
        }

        var data  = $("#post_form").serialize();
        var url = "${ctx}/${userType==1?"sign" : "public"}/administration-leave-apply-form-save.xhtml";
        $.ajax(url, {
            type: "POST",
            data: data,
            dataType:"html",
            cache:false,
            success:function(a) {
                return pageDownloaded(a, url)
            },
            complete:function() {}
        });
    }
</script>